﻿
var validateAdminUrl = SystemLimitUrl + "/user/validateAdmin";
var registerUrl = STSUrl + "/Triage/registTriage";

function validate() {
    var _adminPwd = $("#text_adminpwd").val();
    if (_adminPwd == "") {
        $("#wraning_left").html("管理员密码不能为空");
    } else {
        var _deviceType = getLocalDeviceCookie("LOCAL_DEV_TYPE") == null ? "1" : getLocalDeviceCookie("LOCAL_DEV_TYPE");
        var _hospitalId = getLocalDeviceCookie("HOSPITAL_ID") == null ? "4e66fabafd944e458dc259ce890c31f3" : getLocalDeviceCookie("HOSPITAL_ID");
        var _localIp = getLocalDeviceCookie("LOCAL_DEV_IP");
        var _localMac = getLocalDeviceCookie("LOCAL_DEV_MAC");

        $.ajax({
            url: registerUrl,
            type: 'post',
            data: {
                loginPwd: _adminPwd,
                deviceType: _deviceType,
                hospitalId: _hospitalId,
                ip: _localIp,
                mac: unescape(_localMac),
                constraintTriage: 0
            },
            success: function (d) {
                var resParse = JSON.parse(d);
                if (resParse.status == "0") {//注册成功
                    var _triageId = resParse.data.triageId;
                    var _nextPageKey = resParse.data.nextPageKey;
                    var _token = resParse.data.loginToken;
                    //设置分诊台or叫号器id
                    SetCallingOrTriage_ID(_triageId, _nextPageKey);
                    my_cefsharp.Set_LoginToken_Cef(_token);
                    //跳转页面
                    RedirectByKey(_nextPageKey);

                } else if (resParse.status == "19990") {//密码错误
                    layer.alert(JSON.parse(d).desc, { icon: 2 });
                } else if (resParse.status == "19993") {
                    /*layui弹窗，新加*/
                    layer.open({
                        content: resParse.desc,
                        btn: ['确定', '取消'],
                        yes: function (index, layero) {
                            layer.close(index);
                            $.ajax({
                                url: registerUrl,
                                type: 'post',
                                data: {
                                    loginPwd: _adminPwd,
                                    deviceType: _deviceType,
                                    hospitalId: _hospitalId,
                                    ip: _localIp,
                                    mac: unescape(_localMac),
                                    constraintTriage: 1
                                },
                                success: function (d) {
                                    var resParse1 = JSON.parse(d);
                                    if (resParse1.status == "0") {//注册成功
                                        var _triageId = resParse1.data.triageId;
                                        var _nextPageKey = resParse1.data.nextPageKey;
                                        var _token = resParse1.data.loginToken;
                                        my_cefsharp.Set_LoginToken_Cef(_token);
                                        //设置分诊台or叫号器id
                                        SetCallingOrTriage_ID(_triageId, _nextPageKey);
                                        //跳转页面
                                        RedirectByKey(_nextPageKey);
                                    } else {
                                        layer.alert(resParse1.desc, { icon: 2 });
                                    }
                                },
                                error: function (XMLHttpRequest, textStatus, errorThrown) {
                                    alert("请求失败-" + XMLHttpRequest.status + " textStatus-" + XMLHttpRequest.readyState + " errorThrown-" + textStatus);
                                }
                            });
                        },
                    });
                } else {
                    layer.alert(resParse.desc, { icon: 2 });
                }
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("请求失败-" + XMLHttpRequest.status + " textStatus-" + XMLHttpRequest.readyState + " errorThrown-" + textStatus);
            }
        });

    }

}